package org.qiaice.controller;

import lombok.RequiredArgsConstructor;
import org.qiaice.entity.Setmeal;
import org.qiaice.entity.dto.SetmealDTO;
import org.qiaice.entity.dto.SetmealPageQueryDTO;
import org.qiaice.entity.vo.SetmealVO;
import org.qiaice.result.PageResult;
import org.qiaice.result.Result;
import org.qiaice.service.SetmealService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/admin/setmeal", produces = "application/json; charset=utf-8")
@RequiredArgsConstructor
public class SetmealController {

    private final SetmealService setmealService;

    @GetMapping(value = "/{id}")
    public Result<SetmealVO> queryById(@PathVariable Long id) {
        return Result.ok(setmealService.queryById(id));
    }

    @PostMapping
    public Result<Object> add(@RequestBody SetmealDTO setmealDTO) {
        setmealService.add(setmealDTO);
        return Result.ok(null);
    }

    @PostMapping(value = "/status/{status}")
    public Result<Object> changeStatus(@PathVariable Integer status, Long id) {
        setmealService.updateById(Setmeal.builder().status(status).id(id).build());
        return Result.ok(null);
    }

    @DeleteMapping
    public Result<Object> deleteByIds(@RequestParam List<Long> ids) {
        setmealService.deleteByIds(ids);
        return Result.ok(null);
    }

    @GetMapping(value = "/page")
    public Result<PageResult<SetmealVO>> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
        return Result.ok(setmealService.pageQuery(setmealPageQueryDTO));
    }

    @PutMapping
    public Result<Object> change(@RequestBody SetmealDTO setmealDTO) {
        setmealService.change(setmealDTO);
        return Result.ok(null);
    }
}
